package com.igeekhome.controller.api;

import com.github.pagehelper.PageInfo;
import com.igeekhome.pojo.SWarehouse;
import com.igeekhome.service.IWarehouseService;
import com.igeekhome.util.ResultBean;
import com.igeekhome.util.TableResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 立以宁
 */
@RestController
@RequestMapping("/api/warehouse")
public class WarehouseControllerApi {

    @Autowired
    private IWarehouseService warehouseService;

    @RequestMapping("/list")
    public TableResultBean warehouseList(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10")Integer limit) {
        PageInfo<SWarehouse> sWarehousePageInfo = warehouseService.selectByAll(page, limit);
        Long count  = (Long)sWarehousePageInfo.getTotal();
        return new TableResultBean(0,"成功",count,sWarehousePageInfo.getList());
    }


    @RequestMapping("/add")
    public ResultBean addWarehouse(SWarehouse sWarehouse) {
        warehouseService.saveMethod(sWarehouse);
        return ResultBean.ok();
    }
    @RequestMapping("/delete")
    public ResultBean deleteWarehouse(Integer warehouseId) {
        warehouseService.deleteMethod(warehouseId);
        return ResultBean.ok();
    }
    @RequestMapping("/update")
    public ResultBean updateWarehouse(SWarehouse sWarehouse) {
        warehouseService.updateMethod(sWarehouse);
        return ResultBean.ok();
    }

}
